package cn.hchaojie.camp.javafx.animation;

import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;

public class DemoTimeline extends Application {

	@Override
	public void start(Stage stage) throws Exception {
		Scene scene = new Scene(createContents(), 600, 300);
		
		stage.setScene(scene);
		stage.show();
	}
	
	// 在这里创建页面布局
	private Parent createContents() {
		StackPane stack = new StackPane();
		
		String url = getClass().getResource("mnls.png").toExternalForm();
		ImageView image = new ImageView(url);

		image.setFitHeight(100);
		image.setPreserveRatio(true);
		
		stack.getChildren().add(image);
		
		Timeline timeline = new Timeline();
		timeline.setCycleCount(Timeline.INDEFINITE);
		timeline.setAutoReverse(true);

		KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2);
		KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2);

		Duration duration = Duration.millis(2000);

		KeyFrame keyFrame = new KeyFrame(duration, keyValueX, keyValueY);

		timeline.getKeyFrames().add(keyFrame);
		timeline.play();

		return stack;
	}

	public static void main(String[] args) {
		launch(args);
	}
}
